home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from __future__ import with_statement
- import sys
- import wx
- from wx import Rect, RectS, RectPS, BLACK
- from datetime import datetime
- from gui import skin
- from gui.textutil import default_font, CopyFont
- from gui.skin.skinobjects import SkinColor
- from gui.toolbox import add_image_text
- from gui.uberwidgets.pseudosizer import PseudoSizer
- from gui.uberwidgets.clearlink import ClearLink
- from cgui import SimplePanel
- from common import actions
- from util import do
- link_style = wx.NO_BORDER | wx.HL_ALIGN_LEFT | wx.TRANSPARENT_WINDOW
-
- class Header(SimplePanel):
-
- def __init__(self, parent):
- SimplePanel.__init__(self, parent)
- self.account = None
- self.Bind(wx.EVT_PAINT, self.OnPaint)
- self.linkage = PseudoSizer()
- self.UpdateSkin()
-
-
- def SetAccount(self, account):
- if account is self.account:
- return None
-
- if self.account is not None:
-
- try:
- self.account.unobserve_count(self.Refreshxor)
- except NotImplementedError:
- pass
-
-
- try:
- self.account.unobserve_state(self.Refreshxor)
- except NotImplementedError:
- pass
- except:
- None<EXCEPTION MATCH>NotImplementedError
-
-
- None<EXCEPTION MATCH>NotImplementedError
- self.account = account
- self.icon = account.icon.Resized(16)
- self.linkage.Clear(True)
- for linkfunc in account.header_funcs:
- link = ClearLink(self, -1, linkfunc[0], (lambda l = (linkfunc,): self.do_link(l)), style = link_style, pos = (-400, -400))
- link.NormalColour = link.HoverColour = link.VisitedColour = self.linkfc
- link.Font = self.linkfont
- self.linkage.Add(link)
-
- self.linkage.Layout()
-
- try:
- account.observe_count(self.Refreshxor)
- except NotImplementedError:
- pass
-
-
- try:
- account.observe_state(self.Refreshxor)
- except NotImplementedError:
- pass
-
- self.Refresh(False)
-
-
- def do_link(self, link):
- if len(link) > 2:
- if link[2]:
- wx.GetTopLevelParent(self).Hide()
-
- else:
- wx.GetTopLevelParent(self).Hide()
- if callable(link[1]):
- link[1]()
- else:
- wx.LaunchDefaultBrowser(link[1])
-
-
- def Refreshxor(self, *a):
- self.Refresh(False)
-
-
- def UpdateSkin(self):
- self.padding = wx.Point(4, 4)
- self.headerfont = skin.get('infobox.fonts.header', (lambda : default_font()))
- self.linkfont = CopyFont(skin.get('infobox.fonts.link', (lambda : default_font())), underline = True)
- self.headerfc = skin.get('infobox.fontcolors.navbarheader', (lambda : wx.BLACK))
- self.linkfc = skin.get('infobox.fontcolors.navbarlink', (lambda : wx.BLUE))
- linkposy = self.headerfont.Height + 2 * self.padding[1]
- linkposx = self.padding[0] * 2 + 16
- self.linkage.SetPosition((linkposx, linkposy))
- for link in self.linkage:
- link.NormalColour = link.HoverColour = link.VisitedColour = self.linkfc
- link.Font = self.linkfont
-
- self.linkage.Layout()
- self.bg = skin.get('infobox.backgrounds.header', (lambda : SkinColor(wx.Color(225, 255, 225))))
- self.Size = self.MinSize = wx.Size(-1, self.headerfont.Height + self.linkfont.Height + self.padding.y * 4)
-
-
- def OnPaint(self, event):
- dc = wx.BufferedPaintDC(self)
- rect = RectS(self.Size)
- (padx, pady) = self.padding
- self.bg.Draw(dc, rect)
- dc.Font = self.headerfont
- font_height = self.headerfont.Height
- dc.TextForeground = self.headerfc
- dc.DrawBitmap(self.icon, padx, padx + font_height // 2 - self.icon.Height // 2, True)
- printable = rect.width - padx
- curserx = rect.x + 2 * padx + self.icon.Width
- cursery = rect.y + pady
- dc.DrawLabel(self.account.display_name, wx.Rect(curserx, cursery, printable - curserx, font_height))
- curserx += dc.GetTextExtent(self.account.display_name + ' ')[0]
- if getattr(self.account, 'service', None) != 'twitter':
- None(dc.DrawLabel if not hasattr(self.account, 'count') else '(' + str(self.account.count) + ')', Rect(curserx, cursery, printable - curserx, dc.Font.Height))
-
-
-
-
- class EmailList(wx.VListBox):
-
- def __init__(self, parent):
- wx.VListBox.__init__(self, parent)
- import common.favicons as common
- common.favicons.on_icon += self.OnFaviconReceived
- self.emails = []
- self.account = None
- self.itemheight = 0
- self.SetItemCount(len(self.emails))
- self.linkage = PseudoSizer()
- self.linkage.Show(False)
- self.errorlink = None
- self.UpdateSkin()
- links = [
- ('olink', 'Open', 'OnClickEmail'),
- ('rlink', 'Mark as Read', 'markAsRead'),
- ('alink', 'Archive', 'archive'),
- ('dlink', 'Delete', 'delete'),
- ('slink', 'Report Spam', 'reportSpam')]
- for attr, text, method in links:
- link = ClearLink(self, -1, text, method, style = wx.NO_BORDER | wx.HL_ALIGN_CENTRE)
- link.Font = self.linkfont
- setattr(self, attr, link)
- self.linkage.Add(link)
-
- self.BBind(HYPERLINK = self.OnLink, MOTION = self.OnMouseMotion, LEFT_DCLICK = self.OnDblClick, LEAVE_WINDOW = self.OnMouseOut, MOUSEWHEEL = self.OnMouseWheel, PAINT = self.OnPaint, SHOW = self.OnShow)
- self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
-
-
- def OnFaviconReceived(self, domain):
- get_icon_domain = get_icon_domain
- import common.favicons
- for i, email in enumerate(self.emails):
- if not email.domain:
- continue
-
- if domain == get_icon_domain(email.domain):
- self.RefreshLine(i)
- continue
-
-
-
- def OnMouseWheel(self, event):
- self.ScrollLines(-(event.WheelRotation) // abs(event.WheelRotation))
-
-
- def OnDblClick(self, event):
- self.account.OnClickEmail(self.account.emails[self.Selection])
-
-
- def OnMouseOut(self, event):
- if not self.linkage.Rect.Contains(event.Position) and self.Selection != -1:
- self.RefreshLine(self.Selection)
- self.Selection = -1
- self.linkage.Show(False)
-
-
-
- def OnMouseMotion(self, event):
- i = self.HitTest(event.Position)
- if self.Selection != i:
- oldSelection = self.Selection
- self.Selection = i
- if self.Selection == -1:
- self.linkage.Show(False)
- else:
- self.linkage.Show(True)
- if oldSelection >= 0:
- self.RefreshLine(oldSelection)
-
- if self.Selection >= 0:
- self.RefreshLine(self.Selection)
-
-
-
-
- def OnShow(self, event):
- event.Skip()
- if wx.IsDestroyed(self):
- print >>sys.stderr, 'WARNING: emailpanels.py OnShow called, but is destroyed'
- return None
-
- if not (self.Shown) and self.account is not None:
- self.account.emails.remove_observer(self.ListChanged)
-
- self.Selection = -1
- self.linkage.Show(False)
- self.Refresh(False)
-
-
- def SetAccount(self, account):
- self.ScrollToLine(0)
- self.Selection = -1
- self.linkage.Show(False)
- if self.account is not None:
- self.account.emails.remove_observer(self.ListChanged)
-
- self.account = account
- self.account.emails.add_observer(self.ListChanged)
- self.ListChanged()
- acts = actions.forclass(account)
- fnames = [ _[1] if not isinstance(act, basestring) else None for act in acts ]
- self.olink.Show('open' in fnames)
- self.rlink.Show('markAsRead' in fnames)
- self.alink.Show('archive' in fnames)
- self.dlink.Show('delete' in fnames)
- self.slink.Show('reportSpam' in fnames)
- self.linkage.Layout()
- self.itemheight = [] + self.padding.y * 4 + self.titlefont.Height + self.majorfont.Height + self.linkfont.Height if self.sep else 0
- if account.can_has_preview:
- self.itemheight += self.minorfont.Height + self.padding.y
-
- self.RefreshAll()
- self.Show(True)
- self.Frozen().__enter__()
-
- try:
- self.GrandParent.DoSizeMagic()
- finally:
- pass
-
-
-
- def ListChanged(self, *args, **kwargs):
- i = self.GetFirstVisibleLine()
-
- try:
- topemail = self.emails[i]
- except IndexError:
- topemail = None
-
- self.emails = self.account.emails
- self.Frozen().__enter__()
-
- try:
- self.SetItemCount(len(self.emails))
- self.GrandParent.DoSizeMagic()
- if topemail is not None:
-
- try:
- i = self.emails.index(topemail)
- except ValueError:
- self.Frozen()
- self.Frozen()
- except:
- self.Frozen()<EXCEPTION MATCH>ValueError
-
-
- self.Frozen()
- self.ScrollLines(i)
- finally:
- pass
-
- self.Parent.Refresh(False)
-
-
- def UpdateSkin(self):
- s = skin.get
- self.padding = s('infobox.padding', (lambda : wx.Point(4, 4)))
- self.headerfont = s('infobox.fonts.header', default_font)
- self.titlefont = s('infobox.fonts.title', default_font)
- self.majorfont = s('infobox.fonts.major', default_font)
- self.minorfont = s('infobox.fonts.minor', default_font)
- self.linkfont = CopyFont(s('infobox.fonts.link', default_font), underline = True)
- fc = s('infobox.fontcolors')
- g = fc.get
- self.titlefc = g('title', BLACK)
- self.majorfc = g('major', wx.BLACK)
- self.minorfc = g('minor', wx.Color(128, 128, 128))
- self.linkfc = g('link', wx.BLUE)
- self.hovertitlefc = g('emailhovertitle', self.titlefc)
- self.hovermajorfc = g('emailhovermajor', self.majorfc)
- self.hoverminorfc = g('emailhoverminor', self.minorfc)
- self.hoverlinkfc = g('emailhoverlink', self.linkfc)
- for link in self.linkage:
- link.NormalColour = link.HoverColour = link.VisitedColour = self.hoverlinkfc
- link.Font = self.linkfont
-
- self.linkage.Layout()
- if self.errorlink:
- self.errorlink.Font = self.Parent.Font
- self.errorlink.VisitedColour = self.errorlink.HoverColour = self.errorlink.NormalColour = s('infobox.linkcolor', (lambda : wx.BLUE))
-
- self.bg = s('infobox.backgrounds.email', (lambda : SkinColor(wx.WHITE)))
- self.selbg = s('infobox.backgrounds.emailhover', (lambda : SkinColor(wx.Color(225, 255, 225))))
- self.sep = s('infobox.shortseparatorimage', None)
-
-
- def GetFullHeight(self):
- if not self.ItemCount:
- pass
- return 1 * self.OnMeasureItem(0)
-
-
- def SkimIt(self, it):
- if self.ItemCount:
- h = self.OnMeasureItem(0)
- r = (it // h) * h
- return r
-
- return self.OnMeasureItem(0)
-
-
- def OnMeasureItem(self, n):
- return self.itemheight
-
-
- def OnDrawBackground(self, dc, rect, n):
- if self.Selection == n:
- self.selbg.Draw(dc, rect, n)
- else:
- self.bg.Draw(dc, rect, n)
-
-
- def OnPaint(self, event):
- if self.ItemCount:
- event.Skip()
- return None
-
- dc = wx.BufferedPaintDC(self)
- rect = RectS(self.Size)
- self.OnDrawBackground(dc, rect, 0)
- dc.Font = self.titlefont
- None(dc.DrawLabel if self.account.count else 'No New Email', rect, wx.ALIGN_CENTER)
-
-
- def OnDrawItem(self, dc, rect, n):
- issel = n == self.Selection
- email = self.emails[n]
- pad = self.padding
- sendtime = getattr(email, 'sendtime', None)
- if hasattr(sendtime, 'strftime'):
- strf = sendtime.strftime
- iscurdate = strf('%b %d %y') == datetime.now().strftime('%b %d %y')
- date = strf('%b %d')
- time = strf('%I:%M %p')
- if time[0] == '0':
- time = time[1:]
-
- if iscurdate and getattr(self.account, 'timestamp_is_time', (lambda t: True))(sendtime):
- timestamp = time
- else:
- timestamp = date
- else:
- timestamp = sendtime
- if timestamp is None:
- timestamp = ''
-
- curserx = rect.x + pad.x
- cursery = rect.y + pad.y
- favicon = favicon
- import common.favicons
- d = email.domain
- icon = None if d is not None else None
- iconsize = 16
- if icon is None:
- icon = skin.get('emailpanel.miscicons.defaulticon', None)
-
- if icon is not None:
- icon = icon.Resized(iconsize)
- dc.DrawBitmap(icon, curserx, cursery, True)
-
- curserx += iconsize + pad.x
- dc.Font = self.minorfont
- dc.TextForeground = None if issel else self.minorfc
- tste = dc.GetFullTextExtent(timestamp)
- tsrect = wx.Rect(rect.x + rect.width - tste[0] - pad.x, cursery, tste[0], tste[1] + tste[2] + tste[3])
- dc.DrawTruncatedText(timestamp, tsrect)
- if email.attachments:
- atticon = skin.get('emailpanel.miscicons.attachmenticon', None)
- if atticon is not None:
- count = len(email.attachments)
- if count > 1:
- atticon = add_image_text(atticon, str(count))
-
- dc.DrawBitmap(atticon, tsrect.X - atticon.Width - pad.x, tsrect.Y, True)
-
-
- dc.Font = self.titlefont
- dc.TextForeground = None if issel else self.titlefc
- if not email.fromname:
- pass
- dc.DrawTruncatedText(u'%s' % email.fromemail, Rect(curserx, cursery, rect.Width - (curserx + pad.x) - tsrect.width, dc.Font.Height))
- cursery += dc.Font.Height + self.padding.y
- dc.Font = self.majorfont
- dc.TextForeground = None if issel else self.majorfc
- if not email.subject:
- pass
- dc.DrawTruncatedText(_('(No Subject)'), Rect(curserx, cursery, rect.Width - (curserx + pad.x), dc.Font.Height))
- if self.account.can_has_preview:
- cursery += dc.Font.Height + pad.y
- dc.Font = self.minorfont
- dc.TextForeground = None if issel else self.minorfc
- if not email.content:
- pass
- dc.DrawTruncatedText(_('(No Preview)'), wx.Rect(curserx, cursery, rect.Width - (curserx + pad.x), dc.Font.Height))
-
- if self.sep and n < len(self.emails) - 1:
- self.sep.Draw(dc, wx.RectPS(rect.Position + (2, rect.height - self.sep.Size.height), (rect.width - 4, self.sep.Size.height)))
-
- if issel:
- cursery += dc.Font.Height + pad.y
- self.linkage.SetPosition((curserx, cursery))
-
-
-
- def OnLink(self, event):
- if event.URL == 'OnClickEmail':
- wx.GetTopLevelParent(self).Hide()
-
- getattr(self.account, event.URL)(self.account.emails[self.Selection])
- self.Selection = -1
- self.linkage.Show(False)
-
-
-